package cn.com.guodiantong.ies.utils;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;


/**
 * @ClassName: PropertiesUtils.<br/>
 * @Description: 获取属性文件.<br/>
 *
 * @author Mr.Luoxing
 * @version 1.0.0
 */
public class PropertiesUtils {
	private static Properties props;
	static {
		loadProps();
	}

	synchronized static private void loadProps() {
		props = new Properties();
		InputStream in = null;
		try {
			// 要加载的属性文件
			in = PropertiesUtils.class.getClassLoader().getResourceAsStream("ies.properties");
			props.load(in);
			String load = get("load");
			if (load != null && !"".equals(load)) {
				String[] split = load.split(",");
				for (String path : split) {
					in = PropertiesUtils.class.getClassLoader().getResourceAsStream(path);
					props.load(in);
				}
			}
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		} finally {
			try {
				if (null != in) {
					in.close();
				}
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
	}

	public static String get(String key) {
		if (null == props) {
			loadProps();
		}
		return props.getProperty(key);
	}

	public static String get(String key, String defaultValue) {
		if (null == props) {
			loadProps();
		}
		return props.getProperty(key, defaultValue);
	}
	
}
